﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Speakup;
using TableParsers;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;

namespace Frontend
{
    class UIElementFactory4WeekThemeGrid
    {
        private UIElement Wrap(UIElement control)
        {
            Decorator wrapper = new Decorator();
            wrapper.Child = control;
            wrapper.Margin = new Thickness(3);
            return wrapper;
        }

        public UIElement CreateWeek(int week)
        {
            return Wrap(OnCreateWeek(week));            
        }

        public UIElement CreateClassType(ClassType classType)
        {
            return Wrap(OnCreateClassType(classType));
        }

        public UIElement CreateLevel(ThemeLevel themeLevel)
        {
            return Wrap(OnCreateLevel(themeLevel));
        }

        public UIElement CreateTheme(WeekTheme weekTheme)
        {
            return Wrap(OnCreateTheme(weekTheme));
        }     

        virtual protected UIElement OnCreateWeek(int week)
        {
            TextBlock textBlock = new TextBlock();            
            textBlock.Text = String.Format("Week {0:00}",week);
            textBlock.VerticalAlignment = VerticalAlignment.Center;
            textBlock.HorizontalAlignment = HorizontalAlignment.Center;
            return textBlock;
        }

        virtual protected UIElement OnCreateClassType(ClassType classType)
        {
            TextBlock textBlock = new TextBlock();
            textBlock.Text = classType.ToString();            
            textBlock.VerticalAlignment = VerticalAlignment.Center;
            textBlock.HorizontalAlignment = HorizontalAlignment.Center;
            return textBlock;            
        }

        virtual protected UIElement OnCreateLevel(ThemeLevel themeLevel)
        {
            TextBlock textBlock = new TextBlock();
            textBlock.Text = String.Format("Level {0}", themeLevel.ToString());
            textBlock.VerticalAlignment = VerticalAlignment.Center;
            textBlock.HorizontalAlignment = HorizontalAlignment.Center;
            return textBlock;
        }

        virtual protected UIElement OnCreateTheme(WeekTheme weekTheme)
        {
            TextBlock textBlock = new TextBlock();
            textBlock.TextAlignment = TextAlignment.Center;
            textBlock.TextWrapping = TextWrapping.Wrap;
            textBlock.VerticalAlignment = VerticalAlignment.Center;
            textBlock.HorizontalAlignment = HorizontalAlignment.Center;

            Run textTheme = new Run();
            textTheme.Text = weekTheme.Theme;

            if (weekTheme.Attended)
            {
                textTheme.TextDecorations = TextDecorations.Strikethrough;
                textTheme.Foreground = new SolidColorBrush(Color.FromArgb(100, 20, 20, 20));
                textBlock.Inlines.Add(textTheme);
            }
            else
            {
                textBlock.Inlines.Add(textTheme);
            }

            

            return textBlock;
        }
    }
}
